<template>
	<div id="wx_qrcod" class="inner"></div>
</template>

<script setup name="threeLogin">
	import * as ww from '@wecom/jssdk'
	import loginApi from '@/api/auth/loginApi'
	import { afterLogin } from './util'

	const option = ref({
		el: '#wx_qrcod',
		params: {
			login_type: 'CorpApp',
			appid: 'ww905ad891d7b2fec1',
			agentid: '1000002',
			redirect_uri: 'http://238154dc.r5.cpolar.cn',
			state: 'WWLogin',
			redirect_type: 'callback'
		},
		onCheckWeComLogin({ isWeComLogin }) {
			console.log(1)
			console.log(isWeComLogin)
		},
		async onLoginSuccess({ code }) {
			console.log(2)
			console.log(code)
			let param = {
				code: code
			}
			// 此处调用服务端接口，处理code
			try {
				const loginToken = await loginApi.wechatLogin(param)
				console.log(loginToken)
				const loginAfter = afterLogin(loginToken)
			} catch (err) {}
		},
		onLoginFail({ err }) {
			console.log(3)
			console.log(err)
		}
	})

	const loginAfter = () => {}

	onMounted(() => {
		ww.createWWLoginPanel(option.value)
	})
</script>

<style>
	.nested-enter-active .inner,
	.nested-leave-active .inner {
		transition: all 0.3s ease-in-out;
	}

	.nested-enter-from .inner,
	.nested-leave-to .inner {
		transform: translateX(30px);
		opacity: 0;
	}
</style>
